import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo_ThreadPool {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(3);
        for(int i = 0; i < 1000; i++){
            int id = i;
            service.submit(new Runnable() {
                @Override
                public void run() {
                    Thread current = Thread.currentThread();
                    System.out.println(current.getName() + "执行任务：" + id);
                }
            });
        }
    }
    public static void main1(String[] args) {
        ExecutorService service = Executors.newCachedThreadPool();
        for(int i = 0; i < 1000; i++){
            int id = i;
            service.submit(new Runnable() {
                @Override
                public void run() {
                    Thread current = Thread.currentThread();
                    System.out.println(current.getName() + "执行任务：" + id);
                }
            });
        }
    }
}